package com.easemob.server.example;

import com.easemob.server.example.api.ChatGroupAPI;
import com.easemob.server.example.api.ChatMessageAPI;
import com.easemob.server.example.api.ChatRoomAPI;
import com.easemob.server.example.api.FileAPI;
import com.easemob.server.example.api.IMUserAPI;
import com.easemob.server.example.api.SendMessageAPI;
import com.easemob.server.example.comm.ClientContext;
import com.easemob.server.example.comm.EasemobRestAPIFactory;

public class EasemobInitialize {
	public static EasemobInitialize easemobInitialize = new EasemobInitialize();
	public static EasemobRestAPIFactory factory;
	public static IMUserAPI  USER;
	public static ChatMessageAPI CHAT;
	public static FileAPI FILE;
	public static SendMessageAPI MESSAGE;
	public static ChatGroupAPI CHATGROUP;
	public static ChatRoomAPI CHATROOM;
	
	public static EasemobInitialize getEasemobInitialize() {
		if(factory == null) {
			factory = ClientContext.getInstance().init(ClientContext.INIT_FROM_PROPERTIES).getAPIFactory();
			getEasemobInitialize().setFactory(factory);
		}
		if(CHATROOM == null) {
			CHATROOM = (ChatRoomAPI)factory.newInstance(EasemobRestAPIFactory.CHATROOM_CLASS);
			getEasemobInitialize().setCHATROOM(CHATROOM);
		}
		if(CHATGROUP == null) {
			CHATGROUP = (ChatGroupAPI)factory.newInstance(EasemobRestAPIFactory.CHATGROUP_CLASS);
			getEasemobInitialize().setCHATGROUP(CHATGROUP);
		}
		if(USER == null) {
			USER = (IMUserAPI)factory.newInstance(EasemobRestAPIFactory.USER_CLASS);
			getEasemobInitialize().setUSER(USER);
		}
		if(CHAT == null) {
			CHAT = (ChatMessageAPI)factory.newInstance(EasemobRestAPIFactory.MESSAGE_CLASS);
			getEasemobInitialize().setCHAT(CHAT);
		}
		if(FILE == null) {
			FILE = (FileAPI)factory.newInstance(EasemobRestAPIFactory.FILE_CLASS);
			getEasemobInitialize().setFILE(FILE);
		}
		if(MESSAGE == null) {
			MESSAGE = (SendMessageAPI)factory.newInstance(EasemobRestAPIFactory.SEND_MESSAGE_CLASS);
			getEasemobInitialize().setMESSAGE(MESSAGE);
		}
		return easemobInitialize;
	}

	public EasemobRestAPIFactory getFactory() {
		return factory;
	}

	public void setFactory(EasemobRestAPIFactory factory) {
		EasemobInitialize.factory = factory;
	}

	public IMUserAPI getUSER() {
		return USER;
	}

	public void setUSER(IMUserAPI uSER) {
		USER = uSER;
	}

	public ChatMessageAPI getCHAT() {
		return CHAT;
	}

	public void setCHAT(ChatMessageAPI cHAT) {
		CHAT = cHAT;
	}

	public FileAPI getFILE() {
		return FILE;
	}

	public void setFILE(FileAPI fILE) {
		FILE = fILE;
	}

	public SendMessageAPI getMESSAGE() {
		return MESSAGE;
	}

	public void setMESSAGE(SendMessageAPI mESSAGE) {
		MESSAGE = mESSAGE;
	}

	public ChatGroupAPI getCHATGROUP() {
		return CHATGROUP;
	}

	public void setCHATGROUP(ChatGroupAPI cHATGROUP) {
		CHATGROUP = cHATGROUP;
	}

	public ChatRoomAPI getCHATROOM() {
		return CHATROOM;
	}

	public void setCHATROOM(ChatRoomAPI cHATROOM) {
		CHATROOM = cHATROOM;
	}
}
